import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";

import { RefVoucherMedia, RefVoucherMediaGateway, Voucher, VoucherGateway, VoucherGroup, VoucherGroupGateway } from "qqlx-core";
import { VoucherSchema, VoucherGroupSchema, RefVoucherMediaSchema } from "qqlx-cdk";

import { PgDao } from "../../lib/dao.pg.id";
import { PgDaoUUid } from "../../lib/dao.pg.uuid";

@Injectable()
export class VoucherGroupDao extends PgDao<VoucherGroup> {
  constructor(
    @InjectRepository(VoucherGroupSchema)
    readonly repo: Repository<VoucherGroup>,
  ) {
    super({
      repository: repo,
      relations_name: VoucherGroupGateway.relations,
    });
  }
}

@Injectable()
export class VoucherDao extends PgDaoUUid<Voucher> {
  constructor(
    @InjectRepository(VoucherSchema)
    readonly repo: Repository<Voucher>,
  ) {
    super({
      repository: repo,
      relations_name: VoucherGateway.relations,
    });
  }
}

@Injectable()
export class RefVoucherMediaDao extends PgDao<RefVoucherMedia> {
  constructor(
    @InjectRepository(RefVoucherMediaSchema)
    readonly repo: Repository<RefVoucherMedia>,
  ) {
    super({
      repository: repo,
      relations_name: RefVoucherMediaGateway.relations,
    });
  }
}
